package Training;

//import com.sun.org.apache.xpath.internal.operations.String;

import javax.swing.text.StringContent;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Scanner;


public class Test {
    public static void main(String[] args) throws NoSuchMethodException {
//        Phone phone = new Phone();
//        phone.setBrand("OnePlus") ;
//        phone.setColor("Silver");
//        phone.setPrice(5499);
//        phone.call();
//        phone.sendMessage();
//        String s = "13561791284";
//        if(s.equals([1][3-9][0-9]{9})){
//            System.out.println("return true;");
//        }
//        else{
//            System.out.println("return false;");
//        }

        //文件创建
//        String fileName = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File file = new File(fileName);
//        if(!file.exists()){
//            try{
//                file.createNewFile();
//            }
//            catch(IOException e){
//                e.printStackTrace();
//                System.out.println("error");
//            }
//        }
//        else{
//            System.out.println("no way");
//        }
//
        //删除文件
//        String fileName = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File file = new File(fileName);
//        file.delete();

//创建文件夹
//        String fileName = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14"+File.separator+"xxs";
//        File file = new File(fileName);
//        if(!file.exists()){
//            boolean flag = file.mkdirs();
//            if(flag){
//                System.out.println("success!");
//            }
//            else{
//                System.out.println("Fail");
//            }
//        }
//        else{
//            System.out.println("error");
//        }

//        String filepath = "D:"+File.separator+"Career"+File.separator+"Java"+File.separator+"docs";
//        File file = new File(filepath);
//        if(file.isDirectory()){
//
//        }
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File file = new File(filename);
//        if(!file.exists()){
//            try {
//                boolean flag = file.createNewFile();
//                if(flag){
//                    System.out.println("Create Success");
//                }
//                else{
//                    System.out.println("Create Fail");
//                }
//            } catch (IOException e) {
//                throw new RuntimeException(e);
//            }
//        }
//        else{
//            boolean flag = file.delete();
//            if(flag){
//                System.out.println("Delete Success");
//            }
//            else{
//                System.out.println("Delete Fail");
//            }
//        }

        ////遍历所有文件
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp";
//        File file = new File(filename);
////        print(file);
//        print(file);
//    }
//
//    private static void print(File file) {
//        if(file !=null){
//            if(file.isDirectory()){
//                File[] files = file.listFiles();
//                if(files!=null){
//                    for(File f:files){
//                        print(f);
//                    }
//                }
//            }
//            else{
//                System.out.println(file);
//            }
//        }
//    }
        //字符写入
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File file = new File(filename);
//        //使用字节输出流输出内容到指定文件
//        try {
//            OutputStream op = new FileOutputStream(file);
//            //需要输出内容
//            String content = "zhangyang02";
//            //转为字节流
//            byte[] bytes= content.getBytes();
//            op.write(bytes);
//            op.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //字节写入
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File file = new File(filename);
//        OutputStream op = null;
//        try {
//            op = new FileOutputStream(file,true);//加true不覆盖，不加默认false
//            String content = "\t\nzhangyangshishei??";
//            byte[] bytes = content.getBytes();
//            for (int i = 0; i < bytes.length; i++) {
//                op.write(bytes[i]);
//            }
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //字节输入
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            InputStream inputStream = new FileInputStream(file);
//            //存储读到的字节数据
//            byte[] bytes = new byte[(int)file.length()];//或者直接1024,
//            //字节输入流对象读取文件数据
//            //获取长度
//            int length = inputStream.read(bytes);
//            System.out.println(new String(bytes, 0, length));
//            //关闭流资源
//            inputStream.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }

        //test
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            InputStream inputStream = new FileInputStream(file);
//            byte[] bytes = new byte[1024];
//            int temp = 0;
//            int len = 0;
//            while((temp = inputStream.read()) != -1){
//                bytes[len++] = (byte)temp;
//            }
//            System.out.println(new String(bytes));
//            inputStream.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //文件复制
//        String filenameend = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File fileend = new File(filenameend);
//        String filenamestart = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File filestart = new File(filenamestart);
//        OutputStream outputStream = null;
//        InputStream inputStream = null;
//        try {
        //创建流对象
//            outputStream = new FileOutputStream(filenamestart);
//            inputStream = new FileInputStream(filenameend);
//            //
//            byte[] bytes = new byte[1024];
////            System.out.println(inputStream.read(bytes));
////            System.out.println(new String(bytes));
//            int temp = 0;
//            while((temp = inputStream.read(bytes))!=-1){
//                outputStream.write(bytes,0,temp);
//            }
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//        finally {
//            if(inputStream != null){
//                try {
//                    inputStream.close();
//                } catch (IOException e) {
//                    throw new RuntimeException(e);
//                }
//
//            }
//            if(outputStream != null){
//                try {
//                    outputStream.close();
//                } catch (IOException e) {
//                    throw new RuntimeException(e);
//                }
//            }
//        }
        //未完成尝试
//        String filein = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File fileinput = new File(filein);
//        String fileout = "D:"+File.separator+"软件"+File.separator+"tmp"+ File.separator+"class14.txt";
//        File fileoutput = new File(fileout);
//        InputStream inputStream = null;
//        OutputStream outputStream = null;
//        try {
//            inputStream = new FileInputStream(filein);
//            outputStream = new FileOutputStream(fileout);
//            while(())
//        } catch (FileNotFoundException e) {
//            throw new RuntimeException(e);
//        }
        //字符流写入
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            Writer writer = new FileWriter(file);
//            String content = "张扬";
//            writer.write(content);
//            writer.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //尝试成功与追加写入
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            Writer writer = new FileWriter(file,true);
//            String content = "\n你是谁";
//            writer.write(content);
//            writer.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //字符读入
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            Reader reader = new FileReader(file);
//            char[] chars = new char[1024];
//            int len = reader.read(chars);
//            System.out.println(new String(chars, 0, len));
//            reader.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //字符读入，自动获取长度
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            Reader reader = new FileReader(file);
//            char[] chars = new char[1024];
//            int len = 0;
//            int temp = 0;
//            while((temp = reader.read())!=-1){
////                System.out.println(temp);
//                chars[len++] = (char)temp;
//
//            }
//            System.out.println(new String(chars, 0, len));
////          System.out.println(new String(chars,0,len));
//
//            reader.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //流的转换,字符流转字节流
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            //创建字节流时才可以选true
//            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file,true));
//            String content = "\n对的";
//            outputStreamWriter.write(content);
//            outputStreamWriter.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //字节流转字符流
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file));
//            char[] chars = new char[1024];
//            int temp = 0;
//            int len = 0;
//            while((temp = inputStreamReader.read())!=-1){
//                chars[len++] = (char)temp;
//            }
//            System.out.println(new String(chars,0,len));
//            inputStreamReader.close();
//        } catch (IOException e) {
//
//        }

//打印流
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
//        File file = new File(filename);
//        try {
//            PrintStream printStream = new PrintStream(new PrintStream(file));
//            printStream.print("ZSADF");
//            printStream.close();
//        } catch (FileNotFoundException e) {
//            throw new RuntimeException(e);
//        }
//        HashSet<String> strings = new HashSet<>();
//        strings.add("1");
//        strings.add("2");
//        strings.add("3");
//        for (String element:strings
//             ) {
//            System.out.println(element);
//        }
//
//        TreeSet<String> treeSet = new TreeSet<>();
//        treeSet.add("1");
//        treeSet.add("2");
//        treeSet.add("3");
//        treeSet.add("4");
        //失败,未完成
//        TreeSet<Person> personTreeSet = new TreeSet<Person>(
//                public int compare(Person person1,Person person2){
//                    if(person1.getAge()>person2.getAge){
//                        return 1;
//                    }
//                    else if(person1.getAge()<person2.getAge()){
//                        return -1;
//            }
//                    else{
//                        return person1.getAge().compareto(person2.getAge());
//                    }
//
//        }
//        );
//        Person person1 = new Person();
//        Person person2 = new Person();
//        person1.setAge(10);
//        person2.setAge(20);

//        HashMap_learning<String, String> hashMap = new HashMap_learning<>();
//        hashMap.put("name","zhangyang");
//        System.out.println(hashMap);
//        ArrayList<String> list = new ArrayList<>();
//        list.add("1");
//        list.add("3");
//        list.add("5");
//        System.out.println(list);
//        MyList myList = new MyList();
//        Scanner sc = new Scanner(System.in);
//
//        for (int i = 0; i < 10; i++) {
//            myList.add(sc.nextInt());
//        }
//
//        System.out.println("After adding the element:");
//        myList.show();
//
//        Integer remove = myList.remove();
//        System.out.println("Get the element:");
//        System.out.println(remove);
//
//        System.out.println("After getting the element:");
//        myList.show();
//
//        sc.close();
//        ArrayList<Integer> list = new ArrayList<Integer>();
//        list.add(Integer.parseInt("0"));
//        list.add(Integer.parseInt("1"));
//        list.add(Integer.parseInt("2"));
//
//        Solution solution = new Solution();
//        solution.sortPrint(list);
        //获取字节码
//        Class class1;
//        try {
//            class1 = Class.forName("Training.Person");
//        } catch (ClassNotFoundException e) {
//            throw new RuntimeException(e);
//        }
        //获取构造方法
//        Constructor[] declare1 = class1.getDeclaredConstructors();
//        for (Constructor declare11 :
//                declare1) {
//            int count1 = declare11.getParameterCount();
//            System.out.println(count1+"  "+declare11.getName());
//        }
        //指定参数的构造方法
//        Constructor constructor = class1.getConstructor(String.class,int.class);//公共
//        Constructor[] constructorr = class1.getConstructors();//私有构造函数
//        //
        //序列化与反序列化
//        String filename = "D:"+File.separator+"软件"+File.separator+"tmp"+File.separator+"class14"+File.separator+"class14.txt";
////        File file = new File(filename);
//        try {
//            ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(filename));
//            Person zhang = new Person("zhang", 23);
//            objectOutputStream.writeObject(zhang);
//            System.out.println("保存成功");
//            objectOutputStream.flush();
//            objectOutputStream.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        try {
//            ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(filename));
////            objectInputStream.readObject();//读两次是错误的
//            Person readers =(Person) objectInputStream.readObject();
//            System.out.println((readers.getName() + readers.getAge()));
//            objectInputStream.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        1. 有一个铃声接口 Bell ，里面有个 ring 方法。
//        2. 有一个手机类 Cellphone ，具有闹钟功能 alarmClock ，参数是 Bell 类型
//        3. 测试手机类的闹钟功能，通过匿名内部类 ( 对象 ) 作为参数，打印：懒猪起床了
//        4. 再传入另一个匿名内部类 ( 对象 ) ，打印：小伙伴上课了
//        cellphone cellphone = new cellphone();
//        cellphone.alarmClock().ring();
//        cellphone.alarmClock().skl();
//        ResourceBundle resourceBundle = ResourceBundle.getBundle("jdbc");
//        String driverclass = resourceBundle.getString("driverclass");
//        String url = resourceBundle.getString("url");
//        String user = resourceBundle.getString("user");
//        String password = resourceBundle.getString("password");
//        try(Connection connection = DriverManager.getConnection(url,user,password);
//        Statement statement = connection.createStatement();
//        ) {
//            Class.forName(driverclass);
//            String sql = "insert into trytry01(user,pwd)values('Nick','123123')";
//            int count = statement.executeUpdate(sql);
//            System.out.println("影响了数据表" + count + "条数据");
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
        //第二种驱动注册方式
//        String url = "jdbc:mysql://localhost:3306/test01?serverTimezone=GMT&useSSL=false&character=utf-8";
//        String user = "root";
//        String password = "9683269";
//        try(Connection connection = DriverManager.getConnection(url,user,password);
//        Statement statement = connection.createStatement();
//
//        ){
//            String sql = "insert into trytry01(user,pwd)values('zhang','ai')";
//            int count = statement.executeUpdate(sql);
//            System.out.println(count);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        String url = "jdbc:mysql://localhost:3306/test01?serverTimezone=GMT&useSSL=false&character=utf-8";
//        String user = "root";
//        String password = "9683269";
//        String sql = "select * from trytry01";
//        try(Connection connection = DriverManager.getConnection(url,user,password);
//        Statement statement = connection.createStatement();
//        ResultSet resultSet = statement.executeQuery(sql);
//        ){
//            while(resultSet.next()){
//                String user1 = resultSet.getString("user");
//                String pwd = resultSet.getString("pwd");
//                System.out.println(user1 + "\t" + pwd + "\t");
//            }
//        } catch (SQLException e) {
//            throw new RuntimeException(e);
//        }
        ////////////
//        Map<String,String > loginuser = loginUI();
//        boolean flag = loginuserverify(loginuser);
//        System.out.println((flag ? "Success!" : "Fail"));
        //?,自动提交
//        ResourceBundle resourceBundle = ResourceBundle.getBundle("jdbc");
//        String driverclass = resourceBundle.getString("driverclass");
//        String url = resourceBundle.getString("url");
//        String user1 = resourceBundle.getString("user");
//        String password = resourceBundle.getString("password");
////        String sql = "insert into trytry01(user,pwd)values('Yang','123123')";
//        String sql = "select user as name,pwd from trytry01 where user = ?";
//        try(Connection connection = DriverManager.getConnection(url,user1,password);
//        PreparedStatement preparedStatement = connection.prepareStatement(sql);
//        ) {
////            int i = 2/0;
//            preparedStatement.setString(1,"Nick");
//            System.out.println(preparedStatement);
//            ResultSet resultSet = preparedStatement.executeQuery();
//            Class.forName(driverclass);
////            int count = preparedStatement.executeUpdate(sql);
////            System.out.println(count);
//            while(resultSet.next()){
//                String username = resultSet.getString("name");
//                String password1 = resultSet.getString("pwd");
//                System.out.println(username + '\t' + password1);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

    }
}
//    ----------------------------------------------------------------------------------------------------------
//    private static boolean loginuserverify(Map<String ,String >userinfo){
//        boolean flag = false;
//        String username = userinfo.get("username");
//        String password = userinfo.get("password");
//        Connection connection = null;
//        Statement statement = null;
//        ResultSet resultSet = null;
//        try{
//            Class.forName("com.mysql.cj.jdbc.Driver");
//            String url = "jdbc:mysql://localhost:3306/test01?serverTimezone=GMT&useSSL=false&character=utf-8";
//            String user = "root";
//            String pwd = "9683269";
//            connection = DriverManager.getConnection(url,user,pwd);
//            statement = connection.createStatement();
//            String sql = "select * from trytry01 where user ='"+username+"'and pwd ='"+password+"'";
//            resultSet = statement.executeQuery(sql);
//            while(resultSet.next()){
//                flag = true;
//                break;
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        finally {
//           if(resultSet != null){
//               try {
//                   resultSet.close();
//               } catch (SQLException e) {
//                   throw new RuntimeException(e);
//               }
//           }
//           if(statement!=null){
//               try {
//                   statement.close();
//               } catch (SQLException e) {
//                   throw new RuntimeException(e);
//               }
//           }
//           if(connection!=null){
//               try {
//                   connection.close();
//               } catch (SQLException e) {
//                   throw new RuntimeException(e);
//               }
//           }
//
//        }
//        return flag;
//    }
//    private static Map<String,String> loginUI(){
//        Map<String,String > map = new HashMap_learning<>();
//        Scanner scanner = new Scanner(System.in);
//        System.out.println("input username:");
//        String username = scanner.nextLine();
//        System.out.println("input password:");
//        String password = scanner.nextLine();
//        map.put("username",username);
//        map.put("password",password);
//        return map;
//    }
    //-------------------------------------------------------------------------------------------------------------
//    public interface Bell{
//        public void ring();
//        public void skl();
//    }
//    public static class cellphone {
//        public Bell alarmClock(){
//            return new Bell(){
//
//                @Override
//                public void ring() {
//                    System.out.println("qcl");
//                }
//                public void skl(){
//                    System.out.println("skll");
//                }
//            };
//        }
//    }
    //------------------------------------------------------------------------------------------------------
